Imports System.IO
Imports System.ComponentModel
Imports EHaskins.Frc.Dashboard
Imports System.Collections.ObjectModel

Public Class OiDataProcessor
    Inherits DefaultUserDataProcessor
    Implements IOiDataProcessor

    Dim _joysticks As ObservableCollection(Of Joystick)
    Public Sub New()
        SetId(1103, 3)
        Joysticks = New ObservableCollection(Of Joystick)
        For i = 0 To 3
            Joysticks.Add(New Joystick(i))
        Next
    End Sub

    Public Overrides Function Parse(ByVal data() As Byte) As Byte()
        MyBase.Parse(data)

        Return ShallowParse(UserData)
    End Function

    Public Overrides Function ShallowParse(ByVal data As Byte()) As Byte()
        If data IsNot Nothing Then
            Dim reader As New BinaryReader(New MemoryStream(data))
            For Each joystick As Joystick In Joysticks
                joystick.Parse(reader)
            Next
        End If
        Return Nothing
    End Function

    Public Property Joysticks() As ObservableCollection(Of Joystick) Implements IOiDataProcessor.Joysticks
        Get
            Return _joysticks
        End Get
        Private Set(ByVal value As ObservableCollection(Of Joystick))
            _joysticks = value
            RaisePropertyChanged("Joysticks")
            RaisePropertyChanged("Joystick1")
            RaisePropertyChanged("Joystick2")
            RaisePropertyChanged("Joystick3")
            RaisePropertyChanged("Joystick4")
        End Set
    End Property

    Public ReadOnly Property Joystick1() As Joystick Implements IOiDataProcessor.Joystick1
        Get
            Return Joysticks(0)
        End Get
    End Property
    Public ReadOnly Property Joystick2() As Joystick Implements IOiDataProcessor.Joystick2
        Get
            Return Joysticks(1)
        End Get
    End Property
    Public ReadOnly Property Joystick3() As Joystick Implements IOiDataProcessor.Joystick3
        Get
            Return Joysticks(2)
        End Get
    End Property
    Public ReadOnly Property Joystick4() As Joystick Implements IOiDataProcessor.Joystick4
        Get
            Return Joysticks(3)
        End Get
    End Property
End Class
